package com.example.lenovo.zyfypt_329zay.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.lenovo.zyfypt_329zay.R;
import com.example.lenovo.zyfypt_329zay.iface.RegisterListener;
import com.example.lenovo.zyfypt_329zay.model.RegisterModel;

public class RegisterActivity extends AppCompatActivity implements View.OnClickListener {
    private Button btn,btnzc;
    private EditText et1,et2,et3;
    RegisterListener registerListener = new RegisterListener() {
        @Override
        public void onResponse(String msg) {
            if(msg.equals("1")){
                System.out.println("result:"+msg);
                finish();
            }else{
                System.out.println("result:"+msg);
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        Toast.makeText(this,"注册",Toast.LENGTH_SHORT).show();
        init();
    }

    private void init() {
        btn=(Button)findViewById(R.id.button4);
        btnzc=(Button)findViewById(R.id.button3);
        et1=(EditText) findViewById(R.id.editText3);
        et2=(EditText)findViewById(R.id.editText4);
        et3=(EditText)findViewById(R.id.editText5);
        btn.setOnClickListener(this);
        btnzc.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.button4:
                finish();
                break;
        }
        System.out.println("注册——提交");
        RegisterModel registerModel = new RegisterModel();
        registerModel.getResult(et1.getText().toString(), et2.getText().toString(), et3.getText().toString(), registerListener);
    }
}
